﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Entity;
namespace QuanLyPhongGiam
{
    public partial class frmBaoHanLenhTamGiamDieuTraBoSung : Form
    {
        public frmBaoHanLenhTamGiamDieuTraBoSung()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Load dữ liệu đầu tiên cho trang
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form2_Load(object sender, EventArgs e)
        {
            //Lay thong tin nguoi bi can da qua han, va ko co gia tri trong dot tiep theo
            List<BiCan> lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiamDieuTraBoSung();
            LoadListBiCan(lstBiCan, lvQuaHan);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lstBiCan"></param>
        /// <param name="lvHienThi"></param>
        private void LoadListBiCan(List<BiCan> lstBiCan, ListView lvHienThi)
        {
            lvHienThi.Items.Clear();
            foreach (var biCan in lstBiCan)
            {
                ListViewItem item = new ListViewItem(biCan.MaBiCan);
                item.SubItems.Add(biCan.TenBiCan);
                if (Convert.ToInt16(biCan.GioiTinh) == 1)
                    item.SubItems.Add("Nam");
                else
                    item.SubItems.Add("Nu");
                item.SubItems.Add(biCan.NgaySinh.ToString());
                item.SubItems.Add(biCan.NoiSinh);
                item.SubItems.Add(Convert.ToDateTime(biCan.DT_BoSung_TuNgay).ToString("dd/MM/yyyy"));
                item.SubItems.Add(Convert.ToDateTime(biCan.DT_BoSung_DenNgay).ToString("dd/MM/yyyy"));
                lvHienThi.Items.Add(item);
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            this.Close(); frmBaoHanCacGiaiDoan obj = new frmBaoHanCacGiaiDoan();
            obj.Show();
        }
        int pageIndex = 0;
        private void tabControl1_Selected(object sender, TabControlEventArgs e)
        {
            pageIndex = e.TabPageIndex;
            List<BiCan> lstBiCan = null;
            List<BiCan> lstBiCanDenHanTrongTuan = null;
            switch (pageIndex)
            {
                case 0:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiamDieuTraBoSung();
                    LoadListBiCan(lstBiCan, lvQuaHan);
                    break;
                case 1:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiamDieuTraBoSung_DenHanTrongTuan();
                    LoadListBiCan(lstBiCan, lvDenHanTrongTuan);
                    break;
                case 2:
                    lstBiCan = Query.GetAllBiCans_HasOutExpired_TamGiamDieuTraBoSung();
                    lstBiCanDenHanTrongTuan = Query.GetAllBiCans_HasOutExpired_TamGiamDieuTraBoSung_DenHanTrongTuan();
                    lstBiCan.AddRange(lstBiCanDenHanTrongTuan);
                    LoadListBiCan(lstBiCan, lvToanBoDanhSach);
                    break;
            }
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            frmReporttQuaHanTamGiamDieuTraBoSung reportQuaHanTamGiam = new frmReporttQuaHanTamGiamDieuTraBoSung(pageIndex);
            reportQuaHanTamGiam.Show();
            this.Close();
        }
    }
}
